package chelydra.sharelydra.server.web.service;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chelydra.sharelydra.server.web.SLSServlet;
import chelydra.sharelydra.server.ejb.SLSUser;

/**
 *
 * @author SIMO KOUAM Franck
 */
public class SLSChangeProfileServlet extends SLSServlet {

	public SLSChangeProfileServlet() {
		this.action_name="profile";
	}
  
	@Override
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		this.initManager(request);
		SLSUser user=this.initAttributes(request,response);
		if (user!=null) {
			user.setLastName(request.getParameter("lastName"));
			user.setNickname(request.getParameter("nickname"));
			user.setFirstName(request.getParameter("firstName"));
			user.setEmail(request.getParameter("email"));

			if (request.getParameter("hideInSearch").contentEquals("true")) 
				user.setHideInSearch(1);
			else
				user.setHideInSearch(0);

			if (request.getParameter("hideEmail").contentEquals("true"))
				user.setHideEmail(1);
			else
				user.setHideEmail(0);

			user = this.manager.modifyProfile(user);
			request.setAttribute("user", user);
		}
		this.rd.forward(request, response);
  }
}


 
